package cn.csc.module.shop.dal.mysql.audit;

import cn.csc.framework.common.pojo.PageResult;
import cn.csc.framework.mybatis.core.mapper.BaseMapperX;
import cn.csc.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.csc.module.shop.controller.admin.audit.vo.ShopAuditExportReqVO;
import cn.csc.module.shop.controller.admin.audit.vo.ShopAuditPageReqVO;
import cn.csc.module.shop.dal.dataobject.audit.ShopAuditDO;
import org.apache.ibatis.annotations.Mapper;

import java.math.BigInteger;
import java.util.List;

/**
 * 店铺审核记录 Mapper
 *
 * @author liuchuang
 */
@Mapper
public interface ShopAuditMapper extends BaseMapperX<ShopAuditDO> {

    default PageResult<ShopAuditDO> selectPage(ShopAuditPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ShopAuditDO>()
                .eqIfPresent(ShopAuditDO::getShopId, reqVO.getShopId())
                .likeIfPresent(ShopAuditDO::getShopName, reqVO.getShopName())
                .eqIfPresent(ShopAuditDO::getAuditorId, reqVO.getAuditorId())
                .likeIfPresent(ShopAuditDO::getAuditorName, reqVO.getAuditorName())
                .eqIfPresent(ShopAuditDO::getAuditStatus, reqVO.getAuditStatus())
                .eqIfPresent(ShopAuditDO::getAuditComment, reqVO.getAuditComment())
                .betweenIfPresent(ShopAuditDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShopAuditDO::getId));
    }

    default List<ShopAuditDO> selectList(ShopAuditExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ShopAuditDO>()
                .eqIfPresent(ShopAuditDO::getShopId, reqVO.getShopId())
                .likeIfPresent(ShopAuditDO::getShopName, reqVO.getShopName())
                .eqIfPresent(ShopAuditDO::getAuditorId, reqVO.getAuditorId())
                .likeIfPresent(ShopAuditDO::getAuditorName, reqVO.getAuditorName())
                .eqIfPresent(ShopAuditDO::getAuditStatus, reqVO.getAuditStatus())
                .eqIfPresent(ShopAuditDO::getAuditComment, reqVO.getAuditComment())
                .betweenIfPresent(ShopAuditDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShopAuditDO::getId));
    }

    default List<ShopAuditDO> selectListByShopId(BigInteger shopId) {
        return selectList(new LambdaQueryWrapperX<ShopAuditDO>()
                .eq(ShopAuditDO::getShopId, shopId)
                .orderByDesc(ShopAuditDO::getId));
    }

    default ShopAuditDO selectLatestByShopId(BigInteger shopId){
        return selectOne(new LambdaQueryWrapperX<ShopAuditDO>()
                .eq(ShopAuditDO::getShopId, shopId)
                .orderByDesc(ShopAuditDO::getCreateTime)
                .last("limit 1")
        );
    }


}
